Add new function 'mklocaltime'. Define new consts 'unknown_speed' and 'unknown_course'.
authoroliskoli <oliskoli>
Sun, 30 Jul 2006 17:38:41 +0000 (17:38 +0000)
committeroliskoli <oliskoli>
Sun, 30 Jul 2006 17:38:41 +0000 (17:38 +0000)
defs.h
util.c

diff --git a/defs.h b/defs.h
index bae98af0f5846cfdcd60901f109ba31be118a64c..5a3400054ea867811398363f24738f34c58654e6 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -677,6 +677,7 @@ int xasprintf(char **strp, const char *fmt, ...);
 char *strupper(char *src);
 char *strlower(char *src);
 signed int get_tz_offset(void);
+time_t mklocaltime(struct tm *t);
 time_t mkgmtime(struct tm *t);
 time_t current_time(void);
 signed int month_lookup(const char *m);
@@ -798,8 +799,9 @@ int color_to_bbggrr(char *cname);
  * A constant for unknown altitude.   It's tempting to just use zero
  * but that's not very nice for the folks near sea level.
  */
-#define unknown_alt -99999999.0
-
+#define unknown_alt    -99999999.0
+#define unknown_course              -999.0
+#define unknown_speed       -999.0
 /*
  * textfile: buffered OS independent (CRLF,NL,CR) text reader
  */
diff --git a/util.c b/util.c
index b61a12cc06f06a4ebeed4e860bb7726777638131..282ed20c25549a9ebf2c63f057715a242889e912 100644 (file)
--- a/util.c
+++ b/util.c
@@ -25,6 +25,7 @@
 #include <ctype.h>
 #include <errno.h>
 #include <stdarg.h>
+#include <time.h>
 
 static int i_am_little_endian = -1;
 static int doswap(void);
@@ -702,6 +703,26 @@ mkgmtime(struct tm *t)
        return(result);
 }
 
+/*
+ * mklocaltime: same as mktime, but try to recover the "Summer time flag",
+ *              which is evaluated by mktime
+ */
+time_t
+mklocaltime(struct tm *t)
+{
+       time_t result;
+       struct tm check = *t;
+       
+       check.tm_isdst = 0;
+       result = mktime(&check);
+       check = *localtime(&result);
+       if (check.tm_isdst == 1) {      /* DST is in effect */
+               check = *t;
+               check.tm_isdst = 1;
+               result = mktime(&check);
+       }
+       return result;
+}
 
 /*
  * A wrapper for time(2) that allows us to "freeze" time for testing.